clear;
clc;
L = length(a);
r1 = ceil(rand * L);
r2 = ceil(rand * L);
if r1 ~= r2
    s = min([r1, r2]);
    e = max([r1, r2]);
    a1 = a; b1 = b;
    a(s:e) = b1(s:e);
    b(s:e) = a1(s:e);
    for i = [setdiff(1:L, s:e)]
        a2 = a1(~ismember(a1, a));
        b2 = b1(~ismember(b1, b));
        if ~isempty(a2) 
            if ~isempty(find(a(s:e) == a(i), 1))
               a(i) = a2(1);
            end
        end
        if ~isempty(b2)
            if ~isempty( find(b(s:e) == b(i), 1))
                b(i) = b2(1);
            end
        end
    end
end
